package com.xm.xmapp.tools;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.xm.xmapp.response.bean.CarInfoBean;

public class SwapData {


	public static List<CarInfoBean> getNewListData(List<CarInfoBean> list) {

		try {
			ArrayList<CarInfoBean> listData = new ArrayList<CarInfoBean>();
			ArrayList<CarInfoBean> list0 = new ArrayList<CarInfoBean>();
			ArrayList<CarInfoBean> list1 = new ArrayList<CarInfoBean>();
			for (CarInfoBean carInfoBean : list) {
				if (carInfoBean.is_rent == 1) {
					list0.add(carInfoBean);
				} else {
					list1.add(carInfoBean);
				}
			}
			MyComparator myComparator = new MyComparator();
			Collections.sort(list0, myComparator);
			Collections.sort(list1, myComparator);

			listData.addAll(list0);
			listData.addAll(list1);
			return listData;
		} catch (Exception e) {	
		}
		return list;

	}

	private static class MyComparator implements Comparator<CarInfoBean> {

		@Override
		public int compare(CarInfoBean p1, CarInfoBean p2) {
		
			if (p1.getDianLiang() < p2.getDianLiang()) {
				return 1;
			} else if (p1.getDianLiang() > p2.getDianLiang())
				return -1;
			return 0;
		}

	}

	private static class NewMyComparator implements Comparator<CarInfoBean> {

		@Override
		public int compare(CarInfoBean p1, CarInfoBean p2) {
			// TODO Auto-generated method stub
			if (p1.is_rent < p2.is_rent) {
				{
					return 1;
				}
			} else if (p1.is_rent > p2.is_rent) {

				return -1;
			}

			return 0;
		}

	}

}
